import unittest
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class TestWangzhe(unittest.TestCase):

    def setUp(self):
        self.wd = webdriver.Chrome(service=Service(".\chromedriver_win136.exe"))
        self.wd.implicitly_wait(10)

    def tearDown(self):
        self.wd.close()

    def test_weekly_free(self):
        self.wd.get("https://pvp.qq.com/web201605/herolist.shtml")
        # 获取本周免费英雄
        weekly_free = ["嫦娥", "蔡文姬", "安琪拉", "曹操", "白起", "阿轲"]
        radio = self.wd.find_element(
            By.CSS_SELECTOR, "span[class='ms-radio']:first-child"
        )

        time.sleep(1)
        radio.click()
        time.sleep(1)
        # 注意elements_located和all_elements_located的区别
        heros = WebDriverWait(self.wd, 10).until(
            EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".herolist > li"))
        )

        # heros = self.wd.find_elements(By.CSS_SELECTOR, ".herolist > li")
        self.assertEqual(len(heros), 6)
        for h in heros:
            print(h.text.strip())
            self.assertIn(h.text.strip(), weekly_free)


if __name__ == "__main__":
    unittest.main()
